<?php
	
  require_once("../inc/common.php");
  require_once("../inc/functions.php");
  require_once("../class/DBConnection.php");
  
  if($_SERVER['SERVER_NAME'] == "localhost") {
  	DBConnection::connect("../config/connection_local.cfg");
  } else if($_SERVER['SERVER_NAME'] == "sokolzdelov.dadena.com") {
    DBConnection::connect("../config/connection_production.cfg");
  }
  
  require_once("../class/DateFormat.php");
  
  $result = "";
  $news_count = 0;
  
  // přidat výsledky
 
$query = mysql_query("SELECT utk.KOLO, utk.SEZONA FROM utkani utk WHERE utk.odehrano='1' AND utk.soutezni='1' ORDER BY utk.DATUM DESC LIMIT 1");
$fetch = MySQL_Fetch_Array($query);
$kolo = $fetch["KOLO"];
$sezona = $fetch["SEZONA"];

$query = mysql_query("select u.datum as datum, u.b_domaci as gd, u.b_hoste as gh,
        u.kolo as kolo,
				(select m.nazev from muzstvo m where m.id_muzstvo=u.id_domaci) as domaci,
				(select m.nazev from muzstvo m where m.id_muzstvo=u.id_hoste) as hoste
          FROM utkani u WHERE u.soutezni='1' AND u.kolo = '$kolo' AND u.sezona = '$sezona'
          ORDER BY u.datum ASC, u.odehrano DESC");
while($fetch = MySQL_Fetch_Array($query)) {
  $datum = DateFormat::format($fetch["datum"], DF_DDMMYYYY);
  $domaci = $fetch["domaci"];
  $hoste = $fetch["hoste"];
  $gd = $fetch["gd"];
  $gh = $fetch["gh"];
  $result .= "news".$news_count."=".$kolo.".kolo (".$datum.")  ".$domaci." - ".$hoste."  ".$gd.":".$gh."&";
  $news_count ++;
}

if($kolo == 26) {
  $dalsi_kolo = 1;
} else {
  $dalsi_kolo = $kolo + 1;
}

$query = mysql_query("SELECT * FROM utkani utk WHERE utk.SEZONA='".SEASON."' AND utk.kolo='$dalsi_kolo'");

if(mysql_num_rows($query) > 0) {

  $query = mysql_query("select u.datum as datum, u.kolo as kolo,
				(select m.nazev from muzstvo m where m.id_muzstvo=u.id_domaci) as domaci,
				(select m.nazev from muzstvo m where m.id_muzstvo=u.id_hoste) as hoste
          FROM utkani u WHERE u.soutezni='1' AND u.sezona='".SEASON."'
          AND u.kolo = ".$dalsi_kolo." ORDER BY u.datum ASC");
  while($fetch = MySQL_Fetch_Array($query)){
    $datum = DateFormat::format($fetch["datum"], DF_DDMMYYYY);
    $domaci = $fetch["domaci"];
    $hoste = $fetch["hoste"];
    $result .= "news".$news_count."=".$dalsi_kolo.".kolo (".$datum.")  ".$domaci." - ".$hoste."&";
    $news_count ++;
  }
  
}
  // přidat novinky
  
  echo $result;
  DBConnection::disconnect();
?>
